var TYPE_SEARCH =
{
	text: 0,
	date: 1,
	category: 2
};

var ARRAY_SEARCH = function () {	
    this.INPUTs = null;
    this.DATEs = null;
    this.SELECTs = null;    
    this.NUMBERs = null;
    this.COORDINATEs = null;
    this.BUTTONs = null;
    this.TypeAsset = Asset_Type.NONE;
    this.COORDINATE = null; // vi tri point hien tai cua tai san
    // quy hoach
	this.MaVungQHChungField="mavungquyhoachchung",
    this.MaQHChung = "";
    this.MaQHChiTiet = "";
    this.AttrInfo = [];
    // alias name
    this.AliasName = [];
    // layName
    this.layerName = '';
    this.fieldsetID = '';
    this.divAssetID = '';
    this.divAttributes = 'div_Map_Search_Attrs'; // the div chua du lieu
    // spatial query
    this.divSearchSpatials = 'div_Map_Search_SpatialsQuery'; // the div spatial
    // attribute query
    this.divSearchAttrs = 'div_Map_Search_Attributes'; // the div attributes
    // tim kiem chung
    this.divSearchGeneral = 'div_Map_Search_GeneralQuery';
    
    this.tblAttributes = 'div_Map_TableContent'; // table chua du lieu

    // key down textbox
    this.txtKeyDown = function (e) {    	
        // Allow: backspace, delete, tab, escape, and enter
    	var event = e;
        if (event.keyCode == 46 || event.keyCode == 8 || event.keyCode == 9
		    || event.keyCode == 27 || event.keyCode == 13 ||
        // Allow: Ctrl+A
		    (event.keyCode == 65 && event.ctrlKey === true) ||
        // Allow: home, end, left, right
		    (event.keyCode >= 35 && event.keyCode <= 39)) {
            // let it happen, don't do anything
            return;
        }
        // Allow: .
        else if (event.keyCode == 190) {
        	var idElement = "";
        	var ua = $.browser;
            if (!ua.mozilla) idElement = event.srcElement.id;
            else idElement = event.target.id;
            var objElement = document.getElementById(idElement);
            var sText = objElement.value;
            var isDecimal = objElement.getAttribute("IsDecimal");
            if ((sText.indexOf('.') == -1) && (isDecimal == 1)
			    && (sText.length > 0))
                return;
            else
                event.preventDefault();
        } else {
            // Ensure that it is a number and stop the keypress
            if (event.shiftKey || (event.keyCode < 48 || event.keyCode > 57)
			    && (event.keyCode < 96 || event.keyCode > 105)) {
                event.preventDefault();
            }
        }
    };

    this.setChangedText_Attribute = function (targetELement) {
        var idElement = "";        
        var ua = $.browser;
        if (!ua.mozilla) idElement = event.srcElement.id;
        else idElement = targetELement.id;
        var objElement = document.getElementById(idElement);
        var value = objElement.value;
        var alias = null;      	
		for(var j=0;j<this.AliasName.length;j++)
		{
			if(this.AliasName[j].controlID == undefined) continue;
			if(this.AliasName[j].controlID == '') continue;
			if(idElement.toLowerCase().indexOf((this.AliasName[j].controlID + "_search").toLowerCase()) != -1)
			{
				alias=this.AliasName[j];
				break;
			}
		}
        if(alias==null) return;
        this.AttrInfo[alias.Name] = [];
        this.AttrInfo[alias.Name][0] = alias.Name;
        this.AttrInfo[alias.Name][1] = value;
        this.AttrInfo[alias.Name][2] = TYPE_SEARCH.text;
    };
    
    this.setChangedComboBox_Attribute = function(element)
    {
    	var idElement = element;
        var objElement = document.getElementById(idElement);
    	var value = objElement[objElement.selectedIndex].value;
        var alias = null;
		for(var j=0;j<this.AliasName.length;j++)
		{
			if(this.AliasName[j].controlID == undefined) continue;
			if(this.AliasName[j].controlID == '') continue;
			if(idElement.toLowerCase().indexOf((this.AliasName[j].controlID + "_search").toLowerCase()) != -1)
			{
				alias=this.AliasName[j];
				break;
			}
		}
        if(alias==null) return;
        this.AttrInfo[alias.Name] = [];
        if(objElement.selectedIndex != 0)
    	{
            this.AttrInfo[alias.Name][0] = alias.Name;
            this.AttrInfo[alias.Name][1] = value;
            this.AttrInfo[alias.Name][2] = TYPE_SEARCH.category;  
    	}
        if($(objElement).attr('type') == 'hanhchinh')
    	{
        	var idChild = $(objElement).attr('child');
        	getPhuongXa_From_QuanHuyen(idElement, idChild);
    	}	        
    };
        
    this.init = function(objAsset)
    {
    	for (var i = 0; i < this.INPUTs.length; i++) {
            var $target = $(this.INPUTs[i]);
            $target.attr('disabled', false);
            $target.val("");
            if ($target != undefined) {
                $target.change(function (e) {
                	var targetELement = e.target;
                    objAsset.setChangedText_Attribute(targetELement);
                });
            }
        }      
		
        for(var i = 0; i<this.SELECTs.length; i++) {
        	var $target = $(this.SELECTs[i]);
            $target.val("");
            if($target.length > 0) $target.change(function() {
            	searchCurrent.setChangedComboBox_Attribute(this.id);
            });
        }
        
        for (var i = 0; i < this.DATEs.length; i++) {
            var $target = $(this.DATEs[i]);
            $target.val("");
            if($target.length > 0) $target[0].assetsearch = objAsset;

            $target.change(function (e) {
            	var objAssetSearch = this.assetsearch;
                var splitDate = this.value.split('/');
                var year = parseInt(splitDate[2]);
                var month = parseInt(splitDate[1]);
                var day = parseInt(splitDate[0]);
                if (month < 10) month = "0" + month;
                if (day < 10) day = "0" + day;
                var date = year + "-" + month + "-" + day;
                if(base.trim(this.value) == '') date = '';
                var idElement = this.id;
                var objElement = document.getElementById(idElement);
            	var value = date;
                var alias = null;
        		for(var j=0;j<objAssetSearch.AliasName.length;j++)
        		{
        			if(objAssetSearch.AliasName[j].controlID == undefined) continue;
        			if(objAssetSearch.AliasName[j].controlID == '') continue;
        			if(idElement.toLowerCase().indexOf((objAssetSearch.AliasName[j].controlID + "_search").toLowerCase()) != -1)
        			{
        				alias=objAssetSearch.AliasName[j];
        				break;
        			}
        		}
                if(alias==null) return;
                var aliasName = alias.Name;
                // cat nhat truong date
                objAssetSearch.AttrInfo[aliasName] = [];
                objAssetSearch.AttrInfo[aliasName][0] = alias.Name;
                objAssetSearch.AttrInfo[aliasName][1] = value;
                objAssetSearch.AttrInfo[aliasName][2] = TYPE_SEARCH.date;
                
                if($(this).attr('date') == 'from') aliasName = aliasName + 'from';
                else aliasName = aliasName + 'to';
                // cat nhat truong date from - date to
                objAssetSearch.AttrInfo[aliasName] = [];
                objAssetSearch.AttrInfo[aliasName][0] = alias.Name;
                objAssetSearch.AttrInfo[aliasName][1] = value;
                objAssetSearch.AttrInfo[aliasName][2] = TYPE_SEARCH.date;
            });
            
            $target.datepicker({
                numberOfMonths: 1,
                constrainInput: true,
                dateFormat: 'dd/mm/yy',
                showButtonPanel: false,
                hideIfNoPrevNext: true,
                autoSize: false,
                onSelect: function (date) {
                	var objAssetSearch = this.assetsearch;
                    var splitDate = date.split('/');
                    var year = parseInt(splitDate[2]);
                    var month = parseInt(splitDate[1]);
                    var day = parseInt(splitDate[0]);
                    if (month < 10) month = "0" + month;
                    if (day < 10) day = "0" + day;
                    var date = year + "-" + month + "-" + day;
                    var idElement = this.id;
                    var objElement = document.getElementById(idElement);
                	var value = date;
                    var alias = null;
            		for(var j=0;j<objAssetSearch.AliasName.length;j++)
            		{
            			if(objAssetSearch.AliasName[j].controlID == undefined) continue;
            			if(objAssetSearch.AliasName[j].controlID == '') continue;
            			if(idElement.toLowerCase().indexOf((objAssetSearch.AliasName[j].controlID + "_search").toLowerCase()) != -1)
            			{
            				alias=objAssetSearch.AliasName[j];
            				break;
            			}
            		}
                    if(alias==null) return;
                    var aliasName = alias.Name;
                    if($(this).attr('date') == 'from') aliasName = aliasName + 'from';
                    else aliasName = aliasName + 'to';
                    objAssetSearch.AttrInfo[aliasName] = [];
                    objAssetSearch.AttrInfo[aliasName][0] = alias.Name;
                    objAssetSearch.AttrInfo[aliasName][1] = value;
                    objAssetSearch.AttrInfo[aliasName][2] = TYPE_SEARCH.date;
                },
	            onClose: function( selectedDate ) {
                	var objAssetSearch = this.assetsearch;
                    var idElement = this.id;
                    var alias = null;
            		for(var j=0;j<objAssetSearch.AliasName.length;j++)
            		{
            			if(objAssetSearch.AliasName[j].controlID == undefined) continue;
            			if(objAssetSearch.AliasName[j].controlID == '') continue;
            			if(idElement.toLowerCase().indexOf((objAssetSearch.AliasName[j].controlID + "_search").toLowerCase()) != -1)
            			{
            				alias=objAssetSearch.AliasName[j];
            				break;
            			}
            		}
                    if(alias==null) return;
	            	if($(this).attr('date') == 'from') 
                	{
		                $("#" + alias.controlID + "_Search_To").datepicker( "option", "minDate", selectedDate );             	
                	}
                    else 
                	{
                    	$("#" + alias.controlID + "_Search_From").datepicker( "option", "maxDate", selectedDate );
                	}
	              }
            });
        }

        for (var i = 0; i < this.NUMBERs.length; i++) {
            var $target = $(this.NUMBERs[i]);
            $target.keydown(function (e) {
            	var targetELement = e;
                objAsset.txtKeyDown(targetELement);
            });
        }
    };
    
    this.searchAttrs = function()
    {			
    	// an bieu do
    	$('#div_Map_Chart').hide();
    	// an thematic
    	$('.thematic_div').hide();		    	
    	$('.map_div').show();
    	var layerName = this.layerName;
    	var indexLayer = -1;
    	for (var i = 0; i < vectorArray.length; i++) {
    		var vectorItem = vectorArray[i];
    		if(layerName == base.trim(vectorItem.LayerId.toLowerCase()) && !vectorItem.Map_Service)
    		{				
    			indexLayer = vectorItem.IndexLayer;
    			break;
    		}
    	}
    	if(indexLayer == -1) return;
    	var layerSearch = map.layers[indexLayer];
    	var arrFeature = layerSearch.features;
    	var attr = null;
    	var lengthAliasName = this.AliasName.length;
    	var objValue = null;
    	var typeSearch = TYPE_SEARCH.text;
    	var aliasName = '';
    	var arrFeatureSearch = [];
    	var bSearch = true;
    	var bContinue = true;
    	if(layerName == LayerAssetName.quyHoachChung) 
		{
    		var maQHChung = Cookies.getCookie(QHCHUNG_COOKIE);
    		if(maQHChung == null || maQHChung == undefined) maQHChung = '';
    		if(maQHChung != '') arrFeature = layerSearch.getFeaturesByAttribute('mavungquyhoachchung', maQHChung);
		}
    	else if(layerName == LayerAssetName.quyHoachchitiet) 
		{
    		var maQHChung = Cookies.getCookie(QHCHUNG_COOKIE);
    		if(maQHChung == null || maQHChung == undefined) maQHChung = '';
    		if(maQHChung != '') arrFeature = layerSearch.getFeaturesByAttribute('mavungquyhoachchung', maQHChung);
		}
    	
    	/*var sSQL = "(1=1)";
    	for(var j=0;j<lengthAliasName;j++)
		{ 
			bContinue = true;
			aliasName = this.AliasName[j].Name;
			if(this.AttrInfo[aliasName] == undefined) 
			{
				// dinh dang date
				if(this.AttrInfo[aliasName + 'from'] == undefined && this.AttrInfo[aliasName + 'to'] == undefined) bContinue = false;
				else typeSearch = TYPE_SEARCH.date;
			}
			else typeSearch = this.AttrInfo[aliasName][2];
			if(typeSearch == undefined) continue;
			if(!bContinue) continue;
			if(typeSearch == TYPE_SEARCH.text || typeSearch == TYPE_SEARCH.category) // text - category
			{    				
				objValue = this.AttrInfo[aliasName][1];
				if(objValue == null || objValue == '') continue;
				sSQL = sSQL + " and " + aliasName + " like '%" + objValue + "%'"; 
			}
			else // date
			{
				var objValueFrom = this.AttrInfo[aliasName + 'from'];
				var objValueTo = this.AttrInfo[aliasName + 'to'];
				var date = attr[aliasName];   
				if(date == undefined)
				{
					bSearch = false;
					break;
				}
				date = attr[aliasName].substr(0,10);	// vd: 2013-05-25
				if(objValueFrom == undefined)
				{
					if(objValueTo == undefined) continue;
					else 
					{
						objValueTo = objValueTo[1];
	    				objValueTo = objValueTo.substr(0, 10);
					}
				}
				else
				{
					objValueFrom = objValueFrom[1];					
					if(objValueTo == undefined) objValueTo = undefined; //objValueFrom; 
					else
					{
						objValueTo = objValueTo[1];
	    				objValueTo = objValueTo.substr(0, 10);    		
					}
    				objValueFrom = objValueFrom.substr(0, 10);
				}		
				if(objValueFrom == '') objValueFrom = undefined;
				else sSQL = sSQL + " and " + aliasName + " >= '#" + objValue + "#'";
				if(objValueTo == '') objValueTo = undefined;
				else sSQL = sSQL + " and " + aliasName + " <= '#" + objValue + "#'";
			}
		}*/
    	
    	for(i = 0; i < arrFeature.length; i++)
    	{
    		bSearch = true;
    		attr = arrFeature[i].attributes;
    		for(var j=0;j<lengthAliasName;j++)
    		{ 
    			bContinue = true;
    			aliasName = this.AliasName[j].Name;
    			if(this.AttrInfo[aliasName] == undefined) 
    			{
    				// dinh dang date
    				if(this.AttrInfo[aliasName + 'from'] == undefined && this.AttrInfo[aliasName + 'to'] == undefined) bContinue = false;
    				else typeSearch = TYPE_SEARCH.date;
    			}
    			else typeSearch = this.AttrInfo[aliasName][2];
    			if(typeSearch == undefined) continue;
    			if(!bContinue) continue;
    			if(typeSearch == TYPE_SEARCH.text) // text
    			{    				
    				objValue = this.AttrInfo[aliasName][1];
    				if(objValue == null || objValue == '') continue;
    				if(attr[aliasName] == undefined) 
    				{
    					bSearch = false;
    					break;
    				}
    				var str = attr[aliasName].toLowerCase();
    				var re = new RegExp(objValue.toLowerCase(),"gi"); // g: global match - i: ignore case
    				if(str.match(re) == null)
    				{
    					bSearch = false;
    					break;
    				}
    			}
    			else if(typeSearch == TYPE_SEARCH.category) // category
    			{
    				objValue = this.AttrInfo[aliasName][1];
    				if(objValue == null || objValue == '') continue;
    				if(attr[aliasName] == undefined) 
    				{
    					bSearch = false;
    					break;
    				}
    				if(attr[aliasName] != objValue) 
    				{
    					bSearch = false;
    					break;
    				}
    			}
    			else // date
    			{
    				var objValueFrom = this.AttrInfo[aliasName + 'from'];
    				var objValueTo = this.AttrInfo[aliasName + 'to'];
    				var date = attr[aliasName];   
    				if(date == undefined)
					{
    					bSearch = false;
    					break;
					}
    				date = attr[aliasName].substr(0,10);	// vd: 2013-05-25
    				if(objValueFrom == undefined)
    				{
    					if(objValueTo == undefined) continue;
    					else 
    					{
    						objValueTo = objValueTo[1];
    	    				objValueTo = objValueTo.substr(0, 10);    		
    						//objValueFrom = objValueTo;
    					}
    				}
    				else
    				{
    					objValueFrom = objValueFrom[1];					
    					if(objValueTo == undefined) objValueTo = undefined; //objValueFrom; 
    					else
						{
    						objValueTo = objValueTo[1];
    	    				objValueTo = objValueTo.substr(0, 10);    		
						}
        				objValueFrom = objValueFrom.substr(0, 10);
    				}		
    				if(objValueFrom == '') objValueFrom = undefined;
    				if(objValueTo == '') objValueTo = undefined;
    				if(!base.checkDateBetweenRankTime(date, objValueFrom, objValueTo))
    				{
    					bSearch = false;
    					break;
    				}
    			}
    		}
    		if(bSearch) 
    		{
    			var index = arrFeatureSearch.length;
    			arrFeatureSearch[index] = arrFeature[i].attributes;
    			arrFeatureSearch[index]['fid'] = arrFeature[i].fid;
    		}
    	}	
    	MapAction.SearchAttrAction(indexLayer, this.AliasName, arrFeatureSearch);	
    };
    
    this.cancelAll = function() {
		MapAction.HideDialogSearchAttrAction();
		
		for (var i = 0; i < this.INPUTs.length; i++) {
            var $target = $(this.INPUTs[i]);
            $target.val("");
        }      
		
		this.AttrInfo = [];
        for(var i = 0; i<this.SELECTs.length; i++) {
        	var $target = $(this.SELECTs[i]);
            $target.val("");            
        }
        $("#" + this.fieldsetID + " select").uniform();
	};
};
/****************************************/
var searchCurrent = null;

/****** diem cap phep ********/
var searchDIEMCAPPHEP = new ARRAY_SEARCH();

/****** diem vi pham ********/
var searchDIEMVIPHAM = new ARRAY_SEARCH();

/****** quy hoach chung ********/
var searchQHCHUNG = new ARRAY_SEARCH();

/****** quy hoach chung ********/
var searchQHCHITIET = new ARRAY_SEARCH();

/****** chi gioi duong do ********/
var searchCHIGIOIDUONGDO = new ARRAY_SEARCH();

/****** chi gioi xay dung ********/
var searchCHIGIOIXAYDUNG = new ARRAY_SEARCH();

/****** thua dat ********/
var searchTHUADAT = new ARRAY_SEARCH();

/****** bo den *********/
var searchBODEN = new ARRAY_SEARCH();

/****** day dan ********/
var searchDAYDAN = new ARRAY_SEARCH();

/****** tram bien ap ********/
var searchTBA = new ARRAY_SEARCH();

/****** ho ga ********/
var searchHOGA = new ARRAY_SEARCH();

/****** tuyen cong ********/
var searchTUYENCONG = new ARRAY_SEARCH();

var SEARCH_SPATIAL_TYPE =
{
	none: 0,
	thuaDat: 1,
	taisanVung: 2,
	taisanQuanHuyen: 3,
	taisanDagiac: 4,
	thuadatQHChung: 5
};

var SEARCH_SPATIAL = function()
{	
	this.TypeSpatial = SEARCH_SPATIAL_TYPE.none;
    this.divAttributes = 'div_Map_Search_Attrs'; // the div chua du lieu
    // spatial query
    this.divSearchSpatials = 'div_Map_Search_SpatialsQuery'; // the div spatial
    // tim kiem chung
    this.divSearchGeneral = 'div_Map_Search_GeneralQuery';
    // attribute query
    this.divSearchAttrs = 'div_Map_Search_Attributes'; // the div attributes
    this.tblAttributes = 'div_Map_TableContent'; // table chua du lieu
    this.indexLayerSearch = "";

	this.layerActive = null; // lop ban do dc chon de truy van	
	this.featureActive = null; // feature thua dat dc chon
	this.layerGraphics = null; // layer de draw feature tren map - dung de quet
    /****** thua dat ********/
	this.featureBuffer = null; // feature buffer de quet tim doi tuong
	this.featuresQHChung = [];
	this.featuresQHChitiet = [];
	this.featuresChigioiduongdo = [];
	this.featuresChigioixaydung = [];
	this.featuresDaydan = [];
	this.featuresBoden = [];
	this.featuresTBA = [];
	this.featuresHOGA = [];
	this.featuresTUYENCONG = [];
	this.aliasNamesQHChung = [];
	this.aliasNamesQHChitiet = [];
	this.aliasNamesChigioiduongdo = [];
	this.aliasNamesChigioixaydung = [];
	this.aliasNamesDaydan = [];
	this.aliasNamesBoden = [];
	this.aliasNamesTBA = [];
	this.aliasNamesHOGA = [];
	this.aliasNamesTUYENCONG = [];
	this.aliasNamesThuadat = [];
	this.Inputs = [];
	this.divQueryQHChung = 'div_Map_SearchSpatials_Chung_Data';
	this.divQueryQHChitiet = 'div_Map_SearchSpatials_Chitiet_Data';
	this.divQueryChigioiduongdo = 'div_Map_SearchSpatials_Chigioduongdo_Data';
	this.divQueryChigioixaydung = 'div_Map_SearchSpatials_Chigioixaydung_Data';
	this.divQueryDaydan = 'div_Map_SearchSpatials_Daydan_Data';
	this.divQueryBoden = 'div_Map_SearchSpatials_Boden_Data';
	this.divQueryTBA = 'div_Map_SearchSpatials_TBA_Data';
	this.divQueryHOGA = 'div_Map_SearchSpatials_HOGA_Data';
	this.divQueryTUYENCONG = 'div_Map_SearchSpatials_TUYENCONG_Data';
	/***********************/

	this.featureSearchBySelection_District = null; // select by selection - district
	this.aliasNamesSearchBySelection_District = [];
	/****** tai san theo quan/huyen ******/
	this.selectSearchInsideDistrict = '#select_Tool_cbo_district';
	/*************************************/
	
	/****** tai san theo vung dc quet ********/
	this.selectBySelection = null;
	/*****************************************/
	
	/****** tai san theo vung da giac ********/
	this.selectByArea = null;
	/*****************************************/
	
	/****** quy hoach chung ************/
	this.featuresThuadat = []; // so luong thua dat trong 1 vung quy hoach	
	this.txtQHChung_SoThuadat = '#txt_QHChung_SpatialQuery_SoThuadat';
	this.txtQHChung_DTThuadat = '#txt_QHChung_SpatialQuery_DientichThuadat';
	/***********************************/
	
	/****** tai san trong 1 da giac *******/
	this.addControldrawArea = function() {		
		// control ve da giac
		if(this.selectByArea != null) map.removeControl(this.selectByArea);
		this.selectByArea = new OpenLayers.Control.DrawFeature(this.layerGraphics,
				OpenLayers.Handler.Polygon
				);
		this.selectByArea.events.register('featureadded', this.selectByArea, this.eventfeatureaddedselectByArea);
		map.addControl(this.selectByArea);
		MapAction.DeActive();
		this.selectByArea.activate();		
	};
	
	this.eventfeatureaddedselectByArea = function(evt)
	{
		// feature dc ve tren map
		var featureDraw = evt.feature;
		// multypolygon -> polygon
		var geom = featureDraw.geometry;//.components[0];
		// lay tat ca cac tai san nam trong geom
		var i = 0, j = 0, indexLayer = 0, index = 0;
		var geomType = null;
		var feature = null;
		var iLength = 0;
		// remove form
		var formSearch = $('#form_Search_Draw_Polygone_mapleft_menu');
		$(formSearch).html('');
		// tchon lop tai san - header
		var divAssetSearchDrawPolygon = document.createElement('div');
		$(divAssetSearchDrawPolygon).addClass('input input-mdf wd-s1');
		// span
		var spanSearchDrawPolygon = document.createElement('span');
		$(spanSearchDrawPolygon).text(LANGUAGE['search_spatial_selectasset']);
		$(divAssetSearchDrawPolygon).append(spanSearchDrawPolygon);
		$(formSearch).append(divAssetSearchDrawPolygon);
		var featuresAsset = [];
		var bContain = false;
		for(i=0; i<vectorArray.length; i++)
		{
			var vector = vectorArray[i];
			// an lop WMS
			if(vector.Map_Service) continue;
			// an lop hanh chinh
			if(!vector.Display) continue;
			indexLayer = vector.IndexLayer;
			geomType = vectorArray[indexLayer].Geometry_Type;
			this.layerActive = map.layers[indexLayer];
			iLength = this.layerActive.features.length;
			featuresAsset = [];
			index = 0;
			bContain = false;
			for(j=0; j<iLength; j++)
			{
				feature = this.layerActive.features[j];
				switch(geomType)
				{
					case Geometries.Point:
						if(geom.containsPoint(feature.geometry))
						{
							bContain = true;
							featuresAsset[index] = feature.attributes;
							featuresAsset[index]['fid'] = feature.fid;
							index++;
						}
					break;
					default:
						// vi la multyline - multypolygon nen phai chon components[0]
						//if(geom.intersects(feature.geometry.components[0]))
						if(geom.intersects(feature.geometry))
						{
							bContain = true;
							featuresAsset[index] = feature.attributes;
							featuresAsset[index]['fid'] = feature.fid;
							index++;
						}
						break;
				}
			}
			if(bContain)
			{
				var divAssetSearchDrawPolygon = document.createElement('div');
				$(divAssetSearchDrawPolygon).addClass('input input-mdf wd-s1');
				// <input style="width: 25px;" name="rdMapSearchDrawPolygon" type="radio" checked="checked" value="1">Bá»™ Ä‘Ã¨n
				var inputRadioSearchDrawPolygon = document.createElement('input');
				$(inputRadioSearchDrawPolygon).width(25);
				$(inputRadioSearchDrawPolygon).attr('name', 'rdMapSearchDrawPolygon');
				$(inputRadioSearchDrawPolygon).attr('type', 'radio');
				$(inputRadioSearchDrawPolygon).attr('value', vector.IndexLayer);
				inputRadioSearchDrawPolygon.features = featuresAsset;
				// span
				var spanSearchDrawPolygon = document.createElement('span');
				$(spanSearchDrawPolygon).text(vector.Layer_Name);
				$(divAssetSearchDrawPolygon).append(inputRadioSearchDrawPolygon);
				$(divAssetSearchDrawPolygon).append(spanSearchDrawPolygon);
				$(formSearch).append(divAssetSearchDrawPolygon);
			}
		}
	};
	
	this.searchDrawPolygonAction = function() {
    	// an bieu do
    	$('#div_Map_Chart').hide();
    	// an thematic
    	$('.thematic_div').hide();		    	
    	$('.map_div').show();
		var itemChecked = $('#form_Search_Draw_Polygone_mapleft_menu input[type=radio]:checked');
		if(itemChecked.length == 0)
		{
			alert(LANGUAGE['search_spatial_nhaploptaisan']);
			return;
		}

		var i = 0;
		var indexLayer = $(itemChecked).attr('value');
		// lop tai san dc chon
		this.layerActive = map.layers[indexLayer];
		var sLayerName = vectorArray[indexLayer].LayerId;
		// alias theo lop tai san dc chon
		this.aliasNamesSearchBySelection_District = [];
		for (i = 0; i < arrField_Alias.length; i++) {
			if (base.trim(arrField_Alias[i].LayerName.toLowerCase()) == base.trim(sLayerName.toLowerCase())) {
				this.aliasNamesSearchBySelection_District[this.aliasNamesSearchBySelection_District.length] = arrField_Alias[i];
			}
		}
		this.aliasNamesSearchBySelection_District.sort(function(a, b) {
			var x = a.Index - b.Index;
			return x;
		});	
		this.featureSearchBySelection_District = itemChecked[0].features;		
		MapAction.SearchAttrAction(indexLayer, this.aliasNamesSearchBySelection_District, this.featureSearchBySelection_District);
	};
	/******* end tai san trong 1 da giac ******/
	
	/****** tai san theo vung dc quet ********/
	this.onchangSelectBySelection = function() {
		var selectToolSelectLayerSearchBox = $('#select_Tool_cboLayers_geom');
		var valSelection = selectToolSelectLayerSearchBox.val();
		if(valSelection == "0") return;
		this.layerActive = map.layers[indexLayer];
		if(this.selectBySelection != null) map.removeControl(this.selectBySelection);
		this.selectBySelection = new OpenLayers.Control.DrawFeature(this.layerGraphics,
				OpenLayers.Handler.RegularPolygon, {
					handlerOptions : {
						sides : 4,
						irregular : true
					}
				});
		this.selectBySelection.events.register('featureadded', this.selectBySelection, this.eventfeatureaddedSelectBySelection);
		map.addControl(this.selectBySelection);
		MapAction.DeActive();
		this.selectBySelection.activate();
	};
	
	this.eventfeatureaddedSelectBySelection = function(evt) {
		var selectToolSelectLayerSearchBox = $('#select_Tool_cboLayers_geom');
		var indexLayer = selectToolSelectLayerSearchBox.val();
		if(indexLayer == "0") return;
		// feature dc ve tren map
		var featureDraw = evt.feature;
		// multypolygon -> polygon
		var geom = featureDraw.geometry;//.components[0];
		var feature = null;
		this.featureSearchBySelection_District = [];
		this.layerActive = map.layers[indexLayer];
		var sLayerName = vectorArray[indexLayer].LayerId;
		var geomType = vectorArray[indexLayer].Geometry_Type;
		var i = 0, index = 0;
		var iLength = this.layerActive.features.length;

		// xac dinh xem neu layer dc chon co bi an ko?
		var bVisible = true;
		for(i=0; i<vectorArray.length; i++)
		{
			var vector = vectorArray[i];
			if(vector.LayerId == sLayerName && vector.Map_Service)
			{
				bVisible = map.layers[vector.IndexLayer].getVisibility();
				break;
			}
		}
        if (!bVisible) {
        }
        else
    	{
			for(i=0; i<iLength; i++)
			{
				feature = this.layerActive.features[i];
				switch(geomType)
				{
					case Geometries.Point:
						if(geom.containsPoint(feature.geometry))
						{
							this.featureSearchBySelection_District[index] = feature.attributes;
							this.featureSearchBySelection_District[index]['fid'] = feature.fid;	
							index++;
						}
					break;
					default:
						// vi la multyline - multypolygon nen phai chon components[0]
						//if(geom.intersects(feature.geometry.components[0]))
						if(geom.intersects(feature.geometry))
						{
							this.featureSearchBySelection_District[index] = feature.attributes;
							this.featureSearchBySelection_District[index]['fid'] = feature.fid;	
							index++;
						}
						break;
				}
			}
    	}
		if(this.featureSearchBySelection_District.length == 0)
		{
			alert(LANGUAGE['search_spatial_noresults']);
			searchSPATIAL.searchSpatialQueryCancel();
			return;
		}
		// alias theo lop tai san dc chon
		this.aliasNamesSearchBySelection_District = [];
		for (i = 0; i < arrField_Alias.length; i++) {
			if (base.trim(arrField_Alias[i].LayerName.toLowerCase()) == base.trim(sLayerName.toLowerCase())) {
				this.aliasNamesSearchBySelection_District[this.aliasNamesSearchBySelection_District.length] = arrField_Alias[i];
			}
		}
		this.aliasNamesSearchBySelection_District.sort(function(a, b) {
			var x = a.Index - b.Index;
			return x;
		});	
		MapAction.SearchAttrAction(indexLayer, this.aliasNamesSearchBySelection_District, this.featureSearchBySelection_District);
	};
	/********* end tai san theo vung dc quet *******/
	
	/********** tai san theo quan/huyen ********/
	// phong to quan/huyen dc chon & active control select
	this.selectDistrictActive = function() {
		var value = $(this.selectSearchInsideDistrict).val();
		// phoong to da nang
		if(value == "0")
		{
			MapAction.FullExtent();	
			this.featureActive = null;	
		}
		// phong to quan/huyen
		else
		{
			var i = 0;
			for(i=0; i<arrFeatureDistrict.length; i++)
			{
				var feature = arrFeatureDistrict[i];
				var distID = feature.attributes['dist_id'];
				if(distID == value)
				{
					/*var extent = feature.geometry.bounds;
					map.zoomToExtent(extent);*/
					this.featureActive = feature;
					break;
				}
			}
		}
	};
	
	this.searchInsideDistrictAction = function() {
    	// an bieu do
    	$('#div_Map_Chart').hide();
    	// an thematic
    	$('.thematic_div').hide();		    	
    	$('.map_div').show();
		// lay item checked
		var itemChecked = $('#form_Search_Inside_District_mapleft_menu input[type=radio]:checked');
		if(itemChecked.length == 0)
		{
			alert(LANGUAGE['search_spatial_nhaploptaisan']);
			return;
		}
		var i = 0;
		var indexLayer = $(itemChecked).attr('value');
		// lop tai san dc chon
		this.layerActive = map.layers[indexLayer];
		var sLayerName = vectorArray[indexLayer].LayerId;
		// alias theo lop tai san dc chon
		this.aliasNamesSearchBySelection_District = [];
		for (i = 0; i < arrField_Alias.length; i++) {
			if (base.trim(arrField_Alias[i].LayerName.toLowerCase()) == base.trim(sLayerName.toLowerCase())) {
				this.aliasNamesSearchBySelection_District[this.aliasNamesSearchBySelection_District.length] = arrField_Alias[i];
			}
		}
		this.aliasNamesSearchBySelection_District.sort(function(a, b) {
			var x = a.Index - b.Index;
			return x;
		});	
		var arrFeature = [];
		// chon tat
		if(this.featureActive == null)
		{
			arrFeature = this.layerActive.features;
		}
		// chon feature theo maquan
		else
		{			
			// ma quan dc chon
			var valDistID = $(this.selectSearchInsideDistrict).val();
			arrFeature = this.layerActive.getFeaturesByAttribute('maquan', valDistID);
			if(arrFeature.length == 0)
			{
				alert(LANGUAGE['search_spatial_noresults']);
				this.reset();	
				return;
			}
		}

		// set thuoc tin fid cho tung feature de zoomto
		this.featureSearchBySelection_District = [];
		for(i=0; i<arrFeature.length; i++)
		{
			this.featureSearchBySelection_District[i] = arrFeature[i].attributes;
			this.featureSearchBySelection_District[i]['fid'] = arrFeature[i].fid;	
		}
		MapAction.SearchAttrAction(indexLayer, this.aliasNamesSearchBySelection_District, this.featureSearchBySelection_District);	
	};
	
	this.searchSpatialQueryCancel = function() {
		this.featureActive = null;
		this.reset();	
	};
	/************* end tai san theo quan/huyen ********/
	
	this.init = function() {		
		var i = 0;
		for(i=0; i<this.Inputs.length; i++)
		{
			var controlID = $(this.Inputs[i]);
			controlID.attr('readonly', true);
		}		
		
		this.layerGraphics = vectorGraphics_Identify;
		
		// quy hoach chung
		if(this.aliasNamesQHChung.length == 0)
		{
			for (i = 0; i < arrField_Alias.length; i++) {
				if (base.trim(arrField_Alias[i].LayerName.toLowerCase()) == base.trim(LayerAssetName.quyHoachChung.toLowerCase())) {
					this.aliasNamesQHChung[this.aliasNamesQHChung.length] = arrField_Alias[i];
				}
			}
			this.aliasNamesQHChung.sort(function(a, b) {
				var x = a.Index - b.Index;
				return x;
			});	
		}

		// quy hoach chi tiet
		if(this.aliasNamesQHChitiet.length == 0)
		{
			for (i = 0; i < arrField_Alias.length; i++) {
				if (base.trim(arrField_Alias[i].LayerName.toLowerCase()) == base.trim(LayerAssetName.quyHoachchitiet.toLowerCase())) {
					this.aliasNamesQHChitiet[this.aliasNamesQHChitiet.length] = arrField_Alias[i];
				}
			}
			this.aliasNamesQHChitiet.sort(function(a, b) {
				var x = a.Index - b.Index;
				return x;
			});	
		}

		// chi gioi duong do
		if(this.aliasNamesChigioiduongdo.length == 0)
		{
			for (i = 0; i < arrField_Alias.length; i++) {
				if (base.trim(arrField_Alias[i].LayerName.toLowerCase()) == base.trim(LayerAssetName.chiGioiduongdo.toLowerCase())) {
					this.aliasNamesChigioiduongdo[this.aliasNamesChigioiduongdo.length] = arrField_Alias[i];
				}
			}
			this.aliasNamesChigioiduongdo.sort(function(a, b) {
				var x = a.Index - b.Index;
				return x;
			});	
		}

		// chi gioi xay dung
		if(this.aliasNamesChigioixaydung.length == 0)
		{
			for (i = 0; i < arrField_Alias.length; i++) {
				if (base.trim(arrField_Alias[i].LayerName.toLowerCase()) == base.trim(LayerAssetName.chiGioixaydung.toLowerCase())) {
					this.aliasNamesChigioixaydung[this.aliasNamesChigioixaydung.length] = arrField_Alias[i];
				}
			}
			this.aliasNamesChigioixaydung.sort(function(a, b) {
				var x = a.Index - b.Index;
				return x;
			});	
		}

		// day dan
		if(this.aliasNamesDaydan.length == 0)
		{
			for (i = 0; i < arrField_Alias.length; i++) {
				if (base.trim(arrField_Alias[i].LayerName.toLowerCase()) == base.trim(LayerAssetName.dayDan.toLowerCase())) {
					this.aliasNamesDaydan[this.aliasNamesDaydan.length] = arrField_Alias[i];
				}
			}
			this.aliasNamesDaydan.sort(function(a, b) {
				var x = a.Index - b.Index;
				return x;
			});	
		}

		// bo den
		if(this.aliasNamesBoden.length == 0)
		{
			for (i = 0; i < arrField_Alias.length; i++) {
				if (base.trim(arrField_Alias[i].LayerName.toLowerCase()) == base.trim(LayerAssetName.boDen.toLowerCase())) {
					this.aliasNamesBoden[this.aliasNamesBoden.length] = arrField_Alias[i];
				}
			}
			this.aliasNamesBoden.sort(function(a, b) {
				var x = a.Index - b.Index;
				return x;
			});	
		}

		// tram bien ap
		if(this.aliasNamesTBA.length == 0)
		{
			for (i = 0; i < arrField_Alias.length; i++) {
				if (base.trim(arrField_Alias[i].LayerName.toLowerCase()) == base.trim(LayerAssetName.tramBienAp.toLowerCase())) {
					this.aliasNamesTBA[this.aliasNamesTBA.length] = arrField_Alias[i];
				}
			}
			this.aliasNamesTBA.sort(function(a, b) {
				var x = a.Index - b.Index;
				return x;
			});	
		}

		// ho ga
		if(this.aliasNamesHOGA.length == 0)
		{
			for (i = 0; i < arrField_Alias.length; i++) {
				if (base.trim(arrField_Alias[i].LayerName.toLowerCase()) == base.trim(LayerAssetName.hoGa.toLowerCase())) {
					this.aliasNamesHOGA[this.aliasNamesHOGA.length] = arrField_Alias[i];
				}
			}
			this.aliasNamesHOGA.sort(function(a, b) {
				var x = a.Index - b.Index;
				return x;
			});	
		}

		// tuyen cong
		if(this.aliasNamesTUYENCONG.length == 0)
		{
			for (i = 0; i < arrField_Alias.length; i++) {
				if (base.trim(arrField_Alias[i].LayerName.toLowerCase()) == base.trim(LayerAssetName.tuyenCong.toLowerCase())) {
					this.aliasNamesTUYENCONG[this.aliasNamesTUYENCONG.length] = arrField_Alias[i];
				}
			}
			this.aliasNamesTUYENCONG.sort(function(a, b) {
				var x = a.Index - b.Index;
				return x;
			});	
		}
		
		// thua dat
		if(this.aliasNamesThuadat.length == 0)
		{
			for (i = 0; i < arrField_Alias.length; i++) {
				if (base.trim(arrField_Alias[i].LayerName.toLowerCase()) == base.trim(LayerAssetName.thuadat.toLowerCase())) {
					this.aliasNamesThuadat[this.aliasNamesThuadat.length] = arrField_Alias[i];
				}
			}
			this.aliasNamesThuadat.sort(function(a, b) {
				var x = a.Index - b.Index;
				return x;
			});	
		}
	};
	
	this.reset = function() {
		//this.layerActive = null; // lop ban do dc chon de truy van
		this.featuresQHChung = [];
		this.featuresQHChitiet = [];
		this.featuresChigioiduongdo = [];
		this.featuresChigioixaydung = [];
		this.featuresDaydan = [];
		this.featuresBoden = [];
		this.featuresTBA = [];
		this.featuresHOGA = [];
		this.featuresTUYENCONG = [];
		this.featureSearchBySelection_District = [];
		this.init();
		vectorGraphics.removeAllFeatures();
		vectorGraphics_Search.removeAllFeatures();
		$('#' + this.divAttributes).hide();
	};
	
	/********* thua dat **********/
	this.fillDataThuadat = function() {
		if(this.featureActive.attributes['sohieuthuadat'] == undefined) $('#txt_THUADAT_Sohieuthuadat_SpatialQuery').val('undefined');
		else $('#txt_THUADAT_Sohieuthuadat_SpatialQuery').val(this.featureActive.attributes['sohieuthuadat']);
	};
	
	this.clearDataThuadat = function() {
		$('#txt_THUADAT_Sohieuthuadat_SpatialQuery').val('');
		$('#txt_THUADAT_Sohieuthuadat_SpatialQuery').empty();
		this.featureBuffer = null;
	};
	
	this.displayResult = function() {
		if(this.featureActive == null) return;

		this.featuresQHChung = [];
		this.featuresQHChitiet = [];
		this.featuresChigioiduongdo = [];
		this.featuresChigioixaydung = [];
		this.featuresDaydan = [];
		this.featuresBoden = [];
		this.featuresTBA = [];
		this.featuresHOGA = [];
		this.featuresTUYENCONG = [];
		
		var layerQHChung = LayerTool.getLayerFromLayerID(LayerAssetName.quyHoachChung);
		var layerQHChitiet = LayerTool.getLayerFromLayerID(LayerAssetName.quyHoachchitiet);
		var layerQHChigioiduongdo = LayerTool.getLayerFromLayerID(LayerAssetName.chiGioiduongdo);
		var layerQHChigioixaydung = LayerTool.getLayerFromLayerID(LayerAssetName.chiGioixaydung);
		var layerDaydan = LayerTool.getLayerFromLayerID(LayerAssetName.dayDan);
		var layerBoden = LayerTool.getLayerFromLayerID(LayerAssetName.boDen);
		var layerTBA = LayerTool.getLayerFromLayerID(LayerAssetName.tramBienAp);
		var layerHOGA = LayerTool.getLayerFromLayerID(LayerAssetName.hoGa);
		var layerTUYENCONG = LayerTool.getLayerFromLayerID(LayerAssetName.tuyenCong);
		
		var geomActive = this.featureActive.geometry;//.components[0];
		var i = 0;
		
		if(this.featureBuffer != null) 
		{
			geomActive = this.featureBuffer.geometry;//.components[0];
		}
		
		/* tim thua dat nam trong quy hoach chung */
		for (i = 0; i < layerQHChung.features.length; i++) {
			var objFeature = layerQHChung.features[i];
			// multy polygon -> polygon
			var bb = objFeature.geometry;//.components[0];						    
			if (bb.intersects(geomActive)) {
				this.featuresQHChung[this.featuresQHChung.length] = objFeature;
			}
		}
		
		/*********************************************/
		
		/* tim thua dat nam trong quy hoach chi tiet */
		for (i = 0; i < layerQHChitiet.features.length; i++) {
			var objFeature = layerQHChitiet.features[i];
			// multy polygon -> polygon
			var bb = objFeature.geometry;//.components[0];						    
			if (bb.intersects(geomActive)) {
				this.featuresQHChitiet[this.featuresQHChitiet.length] = objFeature;
			}
		}
		/*********************************************/
		
		/* tim thua dat nam tren chi gioi xay dung */
		for (i = 0; i < layerQHChigioixaydung.features.length; i++) {
			var objFeature = layerQHChigioixaydung.features[i];
			// multy line string -> line string
			var bb = objFeature.geometry;//.components[0];						    
			if (bb.intersects(geomActive)) {
				this.featuresChigioixaydung[this.featuresChigioixaydung.length] = objFeature;
			}
		}
		/*********************************************/
		
		/* tim thua dat nam tren chi gioi duong do */
		for (i = 0; i < layerQHChigioiduongdo.features.length; i++) {
			var objFeature = layerQHChigioiduongdo.features[i];
			// multy line string -> line string
			var bb = objFeature.geometry;//.components[0];						    
			if (bb.intersects(geomActive)) {
				this.featuresChigioiduongdo[this.featuresChigioiduongdo.length] = objFeature;
			}
		}
		/*********************************************/		
		
		/* tim thua dat nam tren duong day dien ko */
		for (i = 0; i < layerDaydan.features.length; i++) {
			var objFeature = layerDaydan.features[i];
			// multy line string -> line string
			var bb = objFeature.geometry;//.components[0];						    
			if (bb.intersects(geomActive)) {
				this.featuresDaydan[this.featuresDaydan.length] = objFeature;
			}
		}
		/*********************************************/
		/* tim thua dat nam tren bo den ko */		
		for (i = 0; i < layerBoden.features.length; i++) {
			var objFeature = layerBoden.features[i];
			// dang point
			var bb = objFeature.geometry;//.components[0];						    
			if (geomActive.components[0].containsPoint(bb)) {
				this.featuresBoden[this.featuresBoden.length] = objFeature;
			}
		}
		/*********************************************/		
		/* tim thua dat nam tren tram bien ap ko */
		for (i = 0; i < layerTBA.features.length; i++) {
			var objFeature = layerTBA.features[i];
			// dang point
			var bb = objFeature.geometry;//.components[0];						    
			if (geomActive.components[0].containsPoint(bb)) {
				this.featuresTBA[this.featuresTBA.length] = objFeature;
			}
		}
		/*********************************************/
		/* tim thua dat nam tren ho ga ko */
		for (i = 0; i < layerHOGA.features.length; i++) {
			var objFeature = layerHOGA.features[i];
			// dang point
			var bb = objFeature.geometry;//.components[0];						    
			if (geomActive.components[0].containsPoint(bb)) {
				this.featuresHOGA[this.featuresHOGA.length] = objFeature;
			}
		}
		/*********************************************/
		/* tim thua dat nam tren tuyen cong ko */
		for (i = 0; i < layerTUYENCONG.features.length; i++) {
			var objFeature = layerTUYENCONG.features[i];
			// multy line string -> line string
			var bb = objFeature.geometry;//.components[0];						    
			if (bb.intersects(geomActive)) {
				this.featuresTUYENCONG[this.featuresTUYENCONG.length] = objFeature;
			}
		}
		/*********************************************/
		MapAction.SearchThuadatSpatialAction();
	};
	/********** end thua dat ******************/
	
	/********* tim so thua dat trong 1 vung quy hoach **********/
	this.searchThuadat_Trong_QHChung = function() {
    	// an bieu do
    	$('#div_Map_Chart').hide();
    	// an thematic
    	$('.thematic_div').hide();		    	
    	$('.map_div').show();
		this.featuresThuadat = [];
		var layerThuadat = LayerTool.getLayerFromLayerID(LayerAssetName.thuadat);
		var i = 0, index = 0;
		var dDientichThuadat = 0; // dien tich cac thua dat trong vung quy hoach
		var geomActive = this.featureActive.geometry; // vung quy hoach dc chon
		/* tim thua dat nam trong vung ko */
		for (i = 0; i < layerThuadat.features.length; i++) {
			var objFeature = layerThuadat.features[i];
			// multy polygon -> polygon
			var bb = objFeature.geometry;//.components[0];						    
			if (bb.intersects(geomActive)) {
				index = this.featuresThuadat.length;
				this.featuresThuadat[index] = objFeature.attributes;
				this.featuresThuadat[index]['fid'] = objFeature.fid;
				var dientich = objFeature.attributes['dientich'];
				if(dientich == undefined || dientich == null || base.trim(dientich) == '') dientich = '0';
				dientich = parseFloat(dientich);
				dDientichThuadat += dientich;
			}
		}
		$(this.txtQHChung_SoThuadat).val(this.featuresThuadat.length);
		$(this.txtQHChung_DTThuadat).val(dDientichThuadat);
		
		//MapAction.SearchAttrAction(this.indexLayerSearch, this.aliasNamesThuadat, this.featuresThuadat);	
		MapAction.SearchAttrAction(layerThuadat.IndexLayer, this.aliasNamesThuadat, this.featuresThuadat);		
	};
	
	this.clearDataQHChung_Thuadat = function() {
		this.featureBuffer = null;
	};
	/***********************************************************/
};

var searchSPATIAL = new SEARCH_SPATIAL();


//==============Tim kiem chung====================

function onkeypressTimKiemchung(element,event){
	var evt = event || window.event;	
	if(evt.keyCode == 13)
	{
		timKiemChung();
	}
}

function timKiemChung(){
	// div_Map_Search_GeneralQuery
	var txtSearch = base.getElementById('searchGeneral');
	var searchValue = '';
	if(txtSearch!=null){
		MapAction.ShowDialogSearchGeneralAction();
		searchValue = txtSearch.value;
		if(searchValue == 'Nhập thông tin') searchValue = '';
		var sFileJSP = "timkiem/timkiemchung.jsp";
		 var param = {
				 word: searchValue
		 };
		 
		 $.ajax({
			  type: "POST",
			  url: sPortletJSP + sFileJSP,
			  data: param
			}).done(function(data) {
				data = data.trim();
				$("#div_Map_Search_GeneralQuery").html(data);
				/*$("#results").tablesorter({widthFixed: true, widgets: ['zebra'],
					headers: {
						0: { sorter: false },
						3: { sorter: false },
			            8: { sorter: false },
			            6: { sorter: false },
			            7: { sorter: false }
			        }
				}).tablesorterPager({container: $("#pager123")});*/
			});
	}
}

function zoomGeneral_Quanhuyen(obj)
{
	var value = $(obj).attr('id');
	var layerDistrict = vectorDistricts;
	var feature = layerDistrict.getFeaturesByAttribute('dist_id', value);
	if(feature != null)
	{
		var geom = feature[0].geometry;
		vectorGraphics_Search.removeAllFeatures();
		createPolygonFromGeometry(vectorGraphics_Search, geom);
	}
}

function zoomGeneral_Phuongxa(obj)
{
	var value = $(obj).attr('id');
	var layerCommune = vectorCommune;
	var feature = layerCommune.getFeaturesByAttribute('com_id', value);
	if(feature != null)
	{
		var geom = feature[0].geometry;
		vectorGraphics_Search.removeAllFeatures();
		createPolygonFromGeometry(vectorGraphics_Search, geom);
		map.zoomToExtent(geo.getBounds());
	}
}